package com.example.community.mapper;

import com.example.community.model.Question;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface QuestionMapper {

    @Insert("insert into question (title, description, gmt_create, gmt_modified, creator, tags) values(#{title},#{description},#{gmt_create},#{gmt_modified},#{creator},#{tags})")
    void create(Question question);

    @Select("select count(1) from question")
    Integer count();

    @Select("select * from question where creator = #{userId} order by gmt_create desc limit #{offset},#{size}")
    List<Question> listById(@Param(value = "userId") String userId, @Param(value = "offset") Integer offset, @Param(value = "size")Integer size);

    @Select("select * from question order by gmt_create desc limit #{offset},#{size}")
    List<Question> list(@Param(value = "offset") Integer offset, @Param(value = "size")Integer size);

    @Select("select count(1) from question where creator = #{userId}")
    Integer countById(@Param(value = "userId") String userId);

    @Select("select * from question where id = #{id}")
    Question getById(@Param(value = "id") Integer id);

    @Update("update question set title = #{title}, description = #{description}, gmt_modified = #{gmt_modified}, tags = #{tags} where id = #{id}")
    void update(Question question);
}
